package com.sskj.mine.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.mine.bean.CoinFeeBean;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.ui.activity.WithdrawActivity;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.http.JsonCallBack;


public class WithdrawActivityPresenter extends BasePresenter<WithdrawActivity> {


    /**
     * 获取提现手续费
     *
     * @param pid 币种码
     * @return
     */
    public void getWithdrawFee(String pid) {
        httpService.getWithdrawFee(pid)
                .execute(new JsonCallBack<HttpData<CoinFeeBean>>() {
                    @Override
                    public void onSuccess(Response<HttpData<CoinFeeBean>> response) {
                        HttpData<CoinFeeBean> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.updateCoin(httpData.getData());
                        }
                    }
                });
    }

    /**
     * 提现
     *
     * @param code       验证码
     * @param tradePwd   支付密码
     * @param usdFee     金额
     * @param walletAddr 钱包地址
     * @param stockCode  币种码
     * @return
     */
    public void withdraw(String code, String tradePwd, String usdFee, String walletAddr, String stockCode, String account) {
        httpService.withdraw(code, tradePwd, usdFee, walletAddr, stockCode, account)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.withDrawSuccess();
                        }
                    }
                });
    }

    /**
     * 获取短信验证码---codeType 1代表注册  2代表重置密码
     *
     * @param mobile 手机号
     * @return
     */
    public void sendCode(String mobile) {
        httpService.sendCode(mobile, "2")
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.msg);
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.startCount();
                        }
                    }
                });
    }

    /**
     * 获取邮箱验证码---codeType 1代表注册  2代表重置密码
     *
     * @param email 邮箱号
     * @return
     */
    public void sendEmailCode(String email) {
        httpService.sendEmailCode(email)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.startCount();
                        }
                    }
                });
    }
}
